package com.wuyan.locationdog.ui.device

import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.ext.createEmptyView
import com.blankj.utilcode.util.ActivityUtils
import com.wuyan.locationdog.R
import com.wuyan.locationdog.adapter.DeviceListSetPwdAdapter
import com.wuyan.locationdog.databinding.DeviceSetPwdListActivityBinding
import com.wuyan.locationdog.help.DeviceHelp
import com.wuyan.locationdog.ui.my.MyModifyPwdActivity
import com.wuyan.locationdog.viewmodel.DeviceViewModel


class DeviceSetPwdListActivity : BaseBindingActivity<DeviceSetPwdListActivityBinding>() {
    private val mViewModel: DeviceViewModel by viewModels()

    private val mAdapter by lazy { DeviceListSetPwdAdapter(R.layout.item_device_set_pwd, null) }

    override fun initData() {
        setTitleText("设备登录密码设置")


        binding.apply {


            recyclerView.apply {
                layoutManager = LinearLayoutManager(context)
                adapter = mAdapter.apply {
                    setEmptyView(createEmptyView("暂无数据"))

                    setOnItemClickListener { adapter, view, position ->
                        DeviceHelp.isDeviceModifyPwd = true
                        DeviceHelp.selectDeviceBeanContent = data[position]

                        ActivityUtils.startActivity(MyModifyPwdActivity::class.java)

                    }
                }
            }


        }
    }

    override fun loadNetData() {
        super.loadNetData()

        val map = HashMap<String, Any>()
        map["pageSize"] = 9999
        map["pageNum"] = 1
        mViewModel.deviceListMy(map)
    }

    override fun observe() {
        super.observe()

        mViewModel.deviceListBean.observe(this) {
            mAdapter.setNewInstance(it.content?.toMutableList())
            binding.tvNum.text = mAdapter.data.size.toString()+"个设备"
        }

    }

}